home *** CD-ROM | disk | FTP | other *** search
- Path: severus.mbfys.kun.nl!rhialto
- From: rhialto@mbfys.kun.nl (Olaf Seibert)
- Newsgroups: comp.sys.amiga.programmer
- Subject: Re: x ^= y ^= x ^= y;
- Date: 8 Mar 1996 17:39:07 GMT
- Organization: University of Nijmegen, The Netherlands
- Distribution: world
- Message-ID: <4hprbr$b29@wn1.sci.kun.nl>
- References: <1286.6624T1439T237@cs.ruu.nl> <3Du8y*20g@yaps.rhein.de> <3132C4BE.2D60@cs.ruu.nl> <4h3ivp$966@hasle.sn.no> <2099.6633T1231T2431@cs.ruu.nl> <4hie4f$978@wn1.sci.kun.nl> <1378.6639T1116T760@cs.ruu.nl>
- NNTP-Posting-Host: severus.mbfys.kun.nl
-
- In <1378.6639T1116T760@cs.ruu.nl> wsldanke@cs.ruu.nl (Wessel Dankers) writes:
- >Hmmm. How about the C++ way,
- >x.operator^=(y.operator^=(x.operator^=(y));
- >That would introduce a sequence point, wouldn't it?
-
- The C++ working paper from september does say this about it in
- 5.2.2 Function call [expr.call]:
-
- | 8 The order of evaluation of arguments is unspecified. All side effects
- | of argument expressions take effect before the function is entered.
- | The order of evaluation of the postfix expression and the argument
- | expression list is unspecified.
-
-
- This seems to be what you want. Unless ofcourse somewhere else
- exceptions are made for the built-in types (see below).
-
- Paragraph 1 describes what a function call actually *is*:
-
- | 1 There are two kinds of function call: ordinary function call and mem-
- | ber function3) (_class.mfct_) call. A function call is a postfix
- | expression followed by parentheses containing a possibly empty, comma-
- | separated list of expressions which constitute the arguments to the
- | function. For ordinary function call, the postfix expression shall be
- | a function name, or shall have pointer or reference to a function
- | type. For member function call, the postfix expression shall be an
- | implicit (_class.mfct.nonstatic_, _class.static_) or explicit class
- | member access (_expr.ref_) whose id-expression is a function member
- | name, or a pointer-to-member expression (_expr.mptr.oper_) selecting a
- | function member. The first expression in the postfix expression is
- | then called the object expression, and the call is as a member of the
- | object pointed to or referred to. In the case of an implicit class
- | member access, the implied object is the one pointed to by this.
- | [Note: a member function call of the form f() is interpreted as
- | (*this).f() (see _class.mfct.nonstatic_). ] If a function or member
- | function name is used, the name can be overloaded (_over_), in which
- | case the appropriate function shall be selected according to the rules
- | _________________________
- | 3) A static member function (_class.static_) is an ordinary function.
- |
- | in _over.match_. The function called in a member function call is
- | normally selected according to the static type of the object expres-
- | sion (see _class.derived_), but if that function is virtual the func-
- | tion actually called will be the final overrider (_class.virtual_) of
- | the selected function in the dynamic type of the object expression
- | [Note: the type of the object pointed or referred to by the current
- | value of the object expression. Clause _class.cdtor_ describes the
- | behavior of virtual function calls when the object-expression refers
- | to an object under construction or destruction. ]
-
- | ______________________________________________________________________
- |
- | 5 Expressions [expr]
- |
- | ______________________________________________________________________
- |
- | 1 [Note: this clause defines the syntax, order of evaluation, and mean-
- | ing of expressions. An expression is a sequence of operators and
- | operands that specifies a computation. An expression can result in a
- | value and can cause side effects.
- |
- | 2 Operators can be overloaded, that is, given meaning when applied to
- | expressions of class type (_class_). Uses of overloaded operators are
- | transformed into function calls as described in _over.oper_. Over-
- | loaded operators obey the rules for syntax specified in this clause,
- | but the requirements of operand type, lvalue, and evaluation order are
- | replaced by the rules for function call. Relations between operators,
- | such as ++a meaning a+=1, are not guaranteed for overloaded operators
- | (_over.oper_), and are not guaranteed for operands of type bool.
- | [Example: the left operand of += must not have type bool. ] ]
- |
- | 3 This clause defines the operators when applied to types for which they
- | have not been overloaded. Operator overloading shall not modify the
- | rules for the built-in operators, that is, for operators applied to
- | types for which they are defined by the language itself. However,
- | these built-in operators participate in overload resolution; see
- | _over.match.oper_.
- |
- | 4 Except where noted, the order of evaluation of operands of individual
- | operators and subexpressions of individual expressions, and the order
- | in which side effects take place, is unspecified. Between the previ-
- | ous and next sequence point a scalar object shall have its stored
- | value modified at most once by the evaluation of an expression. Fur-
- | thermore, the prior value shall be accessed only to determine the
- | value to be stored. The requirements of this paragraph shall be met
- | for each allowable ordering of the subexpressions of a full expres-
- | sion; otherwise the behavior is undefined. [Example:
- | i = v[i++]; // the behavior is undefined
- | i = 7,i++,i++; // `i' becomes 9
- |
- | i = ++i + 1; // the behavior is undefined
- | i = i + 1; // the value of 'i' is incremented
- | --end example]
-
- I think that in the above, "Overloaded operators obey the rules for
- syntax specified in this clause, but the requirements of operand
- type, lvalue, and evaluation order are replaced by the rules for
- function call." means that built-in operators are not function calls
- (even if you write them as such), because they are not overloaded. In
- other words: even your rather extreme example would not do what you
- want.
-
- I find the C standard much easier to read...
-
- >Wessel Dankers _\\|//_ <wsldanke@cs.ruu.nl>
- -Olaf.
- --
- ___ Olaf 'Rhialto' Seibert rhialto@mbfys.kun.nl The only excuse
- \X/ for making a useless thing is that one admires it intensely. -O.W.
-